home *** CD-ROM | disk | FTP | other *** search
/ AGA Toolkit '97 / The AGA Toolkit '97.iso / miscellaneous / science / maths / calc / help / builtin < prev    next >
Encoding:
Text File  |  1996-09-07  |  14.1 KB  |  286 lines

  1. Builtin functions
  2.  
  3.     There is a large number of built-in functions.  Many of the
  4.     functions work on several types of arguments, whereas some only
  5.     work for the correct types (e.g., numbers or strings).  In the
  6.     following description, this is indicated by whether or not the
  7.     description refers to values or numbers.  This display is generated
  8.     by the 'show builtin' command.
  9.  
  10.         Name      Args   Description
  11.  
  12.         abs       1-2    absolute value within accuracy b
  13.         acos      1-2    arccosine of a within accuracy b
  14.         acosh     1-2    hyperbolic arccosine of a within accuracy b
  15.         append    2      append value to end of list
  16.         appr      1-2    approximate a with simpler fraction to within b
  17.         arg       1-2    argument (the angle) of complex number
  18.         asin      1-2    arcsine of a within accuracy b
  19.         asinh     1-2    hyperbolic arcsine of a within accuracy b
  20.         assoc     0      create new association array
  21.         atan      1-2    arctangent of a within accuracy b
  22.         atan2     2-3    angle to point (b,a) within accuracy c
  23.         atanh     1-2    hyperbolic arctangent of a within accuracy b
  24.         avg       1+     arithmetic mean of values
  25.         base      0-1    get/set default output base
  26.         bround    1-2    round value a to b number of binary places
  27.         btrunc    1-2    truncate a to b number of binary places
  28.         ceil      1      smallest integer greater than or equal to number
  29.         cfappr    1-2    approximate a within accuracy b using
  30.                 continued fractions
  31.         cfsim     1      simplify number using continued fractions
  32.         char      1      character corresponding to integer value
  33.         cmp       2      compare values returning -1, 0, or 1
  34.         comb      2      combinatorial number a!/b!(a-b)!
  35.         config    1-2    set or read configuration value
  36.         conj      1      complex conjugate of value
  37.         cos       1-2    cosine of value a within accuracy b
  38.         cosh      1-2    hyperbolic cosine of a within accuracy b
  39.         cp        2      cross product of two vectors
  40.         delete    2      delete element from list a at position b
  41.         den       1      denominator of fraction
  42.         det       1      determinant of matrix
  43.         digit     2      digit at specified decimal place of number
  44.         digits    1      number of digits in number
  45.         dp        2      dot product of two vectors
  46.         epsilon   0-1    set or read allowed error for real calculations
  47.         eval      1      evaluate expression from string to value
  48.         exp       1-2    exponential of value a within accuracy b
  49.         fcnt      2      count of times one number divides another
  50.         fib       1      Fibonacci number F(n)
  51.         frem      2      number with all occurrences of factor removed
  52.         fact      1      factorial
  53.         fclose    1      close file
  54.         feof      1      whether EOF reached for file
  55.         ferror    1      whether error occurred for file
  56.         fflush    1      flush output to file
  57.         fgetc     1      read next char from file
  58.         fgetline  1      read next line from file
  59.         files     0-1    return opened file or max number of opened files
  60.         floor     1      greatest integer less than or equal to number
  61.         fopen     2      open file name a in mode b
  62.         fprintf   2+     print formatted output to opened file
  63.         frac      1      fractional part of value
  64.         gcd       1+     greatest common divisor
  65.         gcdrem    2      a divided repeatedly by gcd with b
  66.         hash      1+     return non-negative hash value for one or
  67.                             more values
  68.         highbit   1      high bit number in base 2 representation
  69.         hmean     1+     harmonic mean of values
  70.         hypot     2-3    hypotenuse of right triangle within accuracy c
  71.         ilog      2      integral log of one number with another
  72.         ilog10    1      integral log of a number base 10
  73.         ilog2     1      integral log of a number base 2
  74.         im        1      imaginary part of complex number
  75.         insert    3      insert value c into list a at position b
  76.         int       1      integer part of value
  77.         inverse   1      multiplicative inverse of value
  78.         iroot     2      integer b'th root of a
  79.         isassoc   1      whether a value is an association
  80.         iseven    1      whether a value is an even integer
  81.         isfile    1      whether a value is a file
  82.         isint     1      whether a value is an integer
  83.         islist    1      whether a value is a list
  84.         ismat     1      whether a value is a matrix
  85.         ismult    2      whether a is a multiple of b
  86.         isnull    1      whether a value is the null value
  87.         isnum     1      whether a value is a number
  88.         isobj     1      whether a value is an object
  89.         isodd     1      whether a value is an odd integer
  90.         isqrt     1      integer part of square root
  91.         isreal    1      whether a value is a real number
  92.         isset     2      whether bit b of abs(a) (in base 2) is set
  93.         isstr     1      whether a value is a string
  94.         isrel     2      whether two numbers are relatively prime
  95.         issimple  1      whether value is a simple type
  96.         issq      1      whether or not number is a square
  97.         istype    2      whether the type of a is same as the type of b
  98.         jacobi    2      -1 => a is not quadratic residue mod b
  99.                   1 => b is composite, or a is quad residue of b
  100.         lcm       1+     least common multiple
  101.         lcmfact   1      lcm of all integers up till number
  102.         lfactor   2      lowest prime factor of a in first b primes
  103.         list      0+     create list of specified values
  104.         ln        1-2    natural logarithm of value a within accuracy b
  105.         lowbit    1      low bit number in base 2 representation
  106.         ltol      1-2    leg-to-leg of unit right triangle (sqrt(1 - a^2))
  107.         matdim    1      number of dimensions of matrix
  108.         matfill   2-3    fill matrix with value b (value c on diagonal)
  109.         matmax    2      maximum index of matrix a dim b
  110.         matmin    2      minimum index of matrix a dim b
  111.         mattrans  1      transpose of matrix
  112.         max       1+     maximum value
  113.         meq       3      whether a and b are equal modulo c
  114.         min       1+     minimum value
  115.         minv      2      inverse of a modulo b
  116.         mmin      2      a mod b value with smallest abs value
  117.         mne       3      whether a and b are not equal modulo c
  118.         near      2-3    sign of (abs(a-b) - c)
  119.         norm      1      norm of a value (square of absolute value)
  120.         null      0      null value
  121.         num       1      numerator of fraction
  122.         ord       1      integer corresponding to character value
  123.         param     1      value of parameter n (or parameter count if n
  124.                 is zero)
  125.         perm      2      permutation number a!/(a-b)!
  126.         pfact     1      product of primes up till number
  127.         pi        0-1    value of pi accurate to within epsilon
  128.         places    1      places after decimal point (-1 if infinite)
  129.         pmod      3      mod of a power (a ^ b (mod c))
  130.         polar     2-3    complex value of polar coordinate (a * exp(b*1i))
  131.         poly      2+     (a1,a2,...,an,x) = a1*x^n+a2*x^(n-1)+...+an
  132.         pop       1      pop value from front of list
  133.         power     2-3    value a raised to the power b within accuracy c
  134.         ptest     2      probabilistic primality test
  135.         printf    1+     print formatted output to stdout
  136.         prompt    1      prompt for input line using value a
  137.         push      2      push value onto front of list
  138.         quomod    4      set c and d to quotient and remainder of a
  139.                 divided by b
  140.         rcin      2      convert normal number a to REDC number mod b
  141.         rcmul     3      multiply REDC numbers a and b mod c
  142.         rcout     2      convert REDC number a mod b to normal number
  143.         rcpow     3      raise REDC number a to power b mod c
  144.         rcsq      2      square REDC number a mod b
  145.         re        1      real part of complex number
  146.         remove    1      remove value from end of list
  147.         root      2-3    value a taken to the b'th root within accuracy c
  148.         round     1-2    round value a to b number of decimal places
  149.         rsearch   2-3    reverse search matrix or list for value b
  150.                 starting at index c
  151.         runtime   0      user mode cpu time in seconds
  152.         scale     2      scale value up or down by a power of two
  153.         search    2-3    search matrix or list for value b starting
  154.                 at index c
  155.         sgn       1      sign of value (-1, 0, 1)
  156.         sin       1-2    sine of value a within accuracy b
  157.         sinh      1-2    hyperbolic sine of a within accuracy b
  158.         size      1      total number of elements in value
  159.         sqrt      1-2    square root of value a within accuracy b
  160.         ssq       1+     sum of squares of values
  161.         str       1      simple value converted to string
  162.         strcat    1+     concatenate strings together
  163.         strlen    1      length of string
  164.         strprintf 1+     return formatted output as a string
  165.         substr    3      substring of a from position b for c chars
  166.         swap      2      swap values of variables a and b (can be dangerous)
  167.         tan       1-2    tangent of a within accuracy b
  168.         tanh      1-2    hyperbolic tangent of a within accuracy b
  169.         trunc     1-2    truncate a to b number of decimal places
  170.         xor       1+     logical xor
  171.  
  172.     The config function sets or reads the value of a configuration
  173.     parameter.  The first argument is a string which names the parameter
  174.     to be set or read.  If only one argument is given, then the current
  175.     value of the named parameter is returned.  If two arguments are given,
  176.     then the named parameter is set to the value of the second argument,
  177.     and the old value of the parameter is returned.  Therefore you can
  178.     change a parameter and restore its old value later.  The possible
  179.     parameters are explained in the next section.
  180.  
  181.     The scale function multiplies or divides a number by a power of 2.
  182.     This is used for fractional calculations, unlike the << and >>
  183.     operators, which are only defined for integers.  For example,
  184.     scale(6, -3) is 3/4.
  185.  
  186.     The quomod function is used to obtain both the quotient and remainder
  187.     of a division in one operation.  The first two arguments a and b are
  188.     the numbers to be divided.  The last two arguments c and d are two
  189.     variables which will be assigned the quotient and remainder.  For
  190.     nonnegative arguments, the results are equivalent to computing a//b
  191.     and a%b.  If a is negative and the remainder is nonzero, then the
  192.     quotient will be one less than a//b.  This makes the following three
  193.     properties always hold:  The quotient c is always an integer.  The
  194.     remainder d is always 0 <= d < b.  The equation a = b * c + d always
  195.     holds.  This function returns 0 if there is no remainder, and 1 if
  196.     there is a remainder.  For examples, quomod(10, 3, x, y) sets x to 3,
  197.     y to 1, and returns the value 1, and quomod(-4, 3.14159, x, y) sets x
  198.     to -2, y to 2.28318, and returns the value 1.
  199.  
  200.     The eval function accepts a string argument and evaluates the
  201.     expression represented by the string and returns its value.
  202.     The expression can include function calls and variable references.
  203.     For example, eval("fact(3) + 7") returns 13.  When combined with
  204.     the prompt function, this allows the calculator to read values from
  205.     the user.  For example, x=eval(prompt("Number: ")) sets x to the
  206.     value input by the user.
  207.  
  208.     The digit and isset functions return individual digits of a number,
  209.     either in base 10 or in base 2, where the lowest digit of a number
  210.     is at digit position 0.  For example, digit(5678, 3) is 5, and
  211.     isset(0b1000100, 2) is 1.  Negative digit positions indicate places
  212.     to the right of the decimal or binary point, so that for example,
  213.     digit(3.456, -1) is 4.
  214.  
  215.     The ptest function is a primality testing function.  The first
  216.     argument is the suspected prime to be tested.  The second argument
  217.     is an iteration count.  The function returns 0 if the number is
  218.     definitely not prime, and 1 is the number is probably prime.  The
  219.     chance of a number which is probably prime being actually composite
  220.     is less than 1/4 raised to the power of the iteration count.  For
  221.     example, for a random number p, ptest(p, 10) incorrectly returns 1
  222.     less than once in every million numbers, and you will probably never
  223.     find a number where ptest(p, 20) gives the wrong answer.
  224.  
  225.     The functions rcin, rcmul, rcout, rcpow, and rcsq are used to
  226.     perform modular arithmetic calculations for large odd numbers
  227.     faster than the usual methods.  To do this, you first use the
  228.     rcin function to convert all input values into numbers which are
  229.     in a format called REDC format.  Then you use rcmul, rcsq, and
  230.     rcpow to multiply such numbers together to produce results also
  231.     in REDC format.  Finally, you use rcout to convert a number in
  232.     REDC format back to a normal number.  The addition, subtraction,
  233.     negation, and equality comparison between REDC numbers are done
  234.     using the normal modular methods.  For example, to calculate the
  235.     value 13 * 17 + 1 (mod 11), you could use:
  236.  
  237.         p = 11;
  238.         t1 = rcin(13, p);
  239.         t2 = rcin(17, p);
  240.         t3 = rcin(1, p);
  241.         t4 = rcmul(t1, t2, p);
  242.         t5 = (t4 + t3) % p;
  243.         answer = rcout(t5, p);
  244.  
  245.     The swap function exchanges the values of two variables without
  246.     performing copies.  For example, after:
  247.  
  248.         x = 17;
  249.         y = 19;
  250.         swap(x, y);
  251.  
  252.     then x is 19 and y is 17.  This function should not be used to
  253.     swap a value which is contained within another one.  If this is
  254.     done, then some memory will be lost.  For example, the following
  255.     should not be done:
  256.  
  257.         mat x[5];
  258.         swap(x, x[0]);
  259.  
  260.     The hash function returns a relatively small non-negative integer
  261.     for one or more input values.  The hash values should not be used
  262.     across runs of the calculator, since the algorithms used to generate
  263.     the hash value may change with different versions of the calculator.
  264.  
  265.     The base function allows one to specify how numbers should be
  266.     printer.  The base function provides a numeric shorthand to the
  267.     config("mode") interface.  With no args, base() will return the
  268.     current mode.  With 1 arg, base(val) will set the mode according to
  269.     the arg and return the previous mode.
  270.  
  271.     The following convention is used to declare modes:
  272.  
  273.          base    config
  274.         value    string
  275.  
  276.            2    "binary"    binary fractions
  277.            8    "octal"        octal fractions
  278.           10    "real"        decimal floating point
  279.           16    "hex"        hexadecimal fractions
  280.          -10    "int"        decimal integer
  281.          1/3    "frac"        decimal fractions
  282.         1e20    "exp"        decimal exponential
  283.     
  284.     For convenience, any non-integer value is assumed to mean "frac",
  285.     and any integer >= 2^64 is assumed to mean "exp".
  286.